/**
 * Created by zzy on 2017/10/27.
 */
import {observer} from "mobx-react";
import {observable, action, computed, observe} from 'mobx'
import NetRequestLuo from '../util/NetRequest'

class BannerStore{
    @observable banner=[];
    @observable bannerUrls=[];
    @observable bannerHotSale=[];
    @observable bannerHotSaleUrls=[];
    constructor(){

    }
    @action getBanner(){
        NetRequestLuo.banner('banner').then((data)=>{
            LOG('轮播图banner-----'+JSON.stringify(data));
            this.banner=data;
            this.setBannerUrl();
        });
        NetRequestLuo.banner('hotSale').then((data)=>{
            LOG('轮播图hotSale-----'+JSON.stringify(data));
            this.bannerHotSale=data;
            this.setBannerHotSaleUrls();
        });

    }
    @computed get bannList(){
        return this.banner;
    }
    @action setBannerHotSaleUrls(){
        let hotSaleUrls=[];
        for(var i=0;i<this.bannerHotSale.length;i++){
            let imageUrl=this.bannerHotSale[i].imageUrl;
            hotSaleUrls.push({uri:imageUrl})
        }
        this.bannerHotSaleUrls=hotSaleUrls;
    }
    @action  setBannerUrl(){
        let banners=[];
        for(var i=0;i<this.banner.length;i++){
            let imageUrl=this.banner[i].imageUrl;
            banners.push({uri:imageUrl})
        }
        this.bannerUrls=banners;
    }
}
class BannerItem{
    @observable imageUrl='';
    @observable linkType='';
    @observable linkData='';
    @observable title='';
}
let bannerStore=new BannerStore();
export default bannerStore;